package com.dify.tool.controller;


import com.dify.tool.api.dto.AgentHistoryRecordAddDTO;
import com.dify.tool.api.vo.AgentHistoryRecordVO;
import com.dify.tool.common.model.DefaultResponse;
import com.dify.tool.service.IAgentHistoryRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 智能体历史记录接口 前端控制器
 * </p>
 *
 * @author shl
 * @since 2025-07-28
 */
@Slf4j
@RestController
@RequestMapping("/agent/history")
@Tag(description = "智能体历史记录接口", name = "智能体历史记录接口")
public class AgentHistoryRecordController {

    @Resource
    private IAgentHistoryRecordService iAgentHistoryRecordService;

    /**
     * 新增
     */
    @PostMapping("/add")
    @Operation(summary = "新增")
    public DefaultResponse<?> add(@RequestBody @Valid AgentHistoryRecordAddDTO dto) {
        iAgentHistoryRecordService.add(dto);
        return DefaultResponse.success();
    }

    /**
     * 会话列表
     */
    @PostMapping("/sessionList")
    @Operation(summary = "会话列表")
    public DefaultResponse<List<AgentHistoryRecordVO>> sessionList() {
        return DefaultResponse.success(iAgentHistoryRecordService.sessionList());
    }

    /**
     * 根据会话id查询历史记录
     */
    @PostMapping("/queryBySessionId/{sessionId}")
    @Operation(summary = "根据会话id查询历史记录")
    public DefaultResponse<List<AgentHistoryRecordVO>> queryBySessionId(@PathVariable("sessionId") String sessionId) {
        return DefaultResponse.success(iAgentHistoryRecordService.queryBySessionId(sessionId));
    }

    /**
     * 点赞差评
     */
    @PostMapping("/likeOrDislike/{messageId}/{isLike}")
    @Operation(summary = "点赞差评")
    public DefaultResponse<?> likeOrDislike(@PathVariable("messageId") Long messageId, @PathVariable("isLike") Integer isLike) {
        iAgentHistoryRecordService.likeOrDislike(messageId, isLike);
        return DefaultResponse.success();
    }
}
